from selenium import webdriver
import time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

driver = webdriver.Edge()
driver.get('https://www.jiuxian.com/')
driver.maximize_window()
# 点击请登录
driver.find_element(By.CLASS_NAME, 'headerLogin').click()
# 输入用户名
driver.find_element(By.ID, 'userName').send_keys('15523615751')
# 输入密码
driver.find_element(By.ID, 'password').send_keys('lj070130.')
time.sleep(15)
# 点击登录
driver.find_element(By.NAME, 'bi_Usuallogin').click()
time.sleep(3)
# 确定
driver.find_element(By.ID, 'bindSub').click()
time.sleep(3)
# 断言
dy = driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
print(dy)
# 输入框
driver.find_element(By.ID,'wd').send_keys('国台')
# 搜索
driver.find_element(By.CLASS_NAME,'search-btn').click()
# 断言
dy2 = driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[2]/div[2]/a').text
print(dy2)
# 进入店铺
driver.find_element(By.XPATH,'//a[@href=" http://shop.jiuxian.com/brand-20.htm "]').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(5)
# 下滑
driver.execute_script('window.scrollTo(0,2000)')
time.sleep(2)
# 加入购物车
driver.find_element(By.XPATH,'//*[@id="layoutContain"]/div/div/div/div/div/map[1]/area').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(5)
# 到货通知
driver.find_element(By.ID, 'addToCartForDetail').click()
time.sleep(2)
# clear清空在输入
# driver.find_element(By.CLASS_NAME, 'notify-form').clear()
# time.sleep(2)
# driver.find_element(By.CLASS_NAME, 'notify-form').send_keys('3516922232@qq.com')
# time.sleep(2)

# 无下划线backspace
driver.find_element(By.CLASS_NAME, 'notify-form').send_keys(Keys.BACKSPACE)
time.sleep(2)
driver.find_element(By.CLASS_NAME, 'notify-form').send_keys('3516922232@qq.com')
time.sleep(2)

# # 有下划线backspace
# driver.find_element(By.CLASS_NAME, 'notify-form').send_keys(Keys.BACK_SPACE)
# time.sleep(2)
# driver.find_element(By.CLASS_NAME, 'notify-form').send_keys('3516922232@qq.com')
# time.sleep(2)




# # 点击QQ登录
# driver.find_element(By.XPATH, '//*[@id="loginform"]/div/div/div/div/div[1]/div[4]/div/a[1]/i').click()
# f = driver.find_element(By.ID, 'ptlogin_iframe')
# driver.switch_to.frame(f)
# time.sleep(1)
# driver.find_element(By.CLASS_NAME, 'img_out_focus').click()